package cn.juforg.airled;

import android.app.Activity;
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;

public class AirLEDViewer extends Activity {
	
	SharedPreferences shpf;			//配置信息
	AirLED airLED = new AirLED(this);
	
	boolean smallLED;
	
	String ledText;
	int color;
	int speed;
	String font;
	
	
	Paint highlightColor = new Paint();
	Paint darkColor = new Paint();
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);//全屏显示
//        requestWindowFeature(Window.FEATURE_NO_TITLE);
//        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);//由物理感应器决定显示方向，它取决于用户如何持有设备
        setContentView(airLED);
        //airLED = (AirLED) findViewById(R.id.AirLED);
        //shpf = PreferenceManager.getDefaultSharedPreferences(this);
        
//        Bundle localBundle = getIntent().getExtras();
//        setupViewFromIntent(airLED, localBundle);
//        setupOverlayColors();
//        Bitmap localBitmap;
//        if (smallLED) {
//        	localBitmap = createOverlayImage(16, createDotBasedOnSize(16));
//		} else {
//			localBitmap = createOverlayImage(10, createDotBasedOnSize(10));
//		}
        //((ImageView)findViewById(R.id.Overlay)).setImageBitmap(localBitmap);
    }
    
    private void setupViewFromIntent(AirLED paramAirLED, Bundle paramBundle){
    	this.ledText = "abadf";
    	this.color = 1;
    	this.speed = 2;
    	this.font= "adsfa";
    	paramAirLED.setLedText(this.ledText);
    	paramAirLED.setColor(this.color);
    	paramAirLED.setSpeed(this.speed);
    	paramAirLED.setFont(this.font);
    }
    
    private void setupOverlayColors(){
    	this.highlightColor.setColor(Color.BLUE);
    	this.highlightColor.setStyle(Paint.Style.FILL);
    	this.highlightColor.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.LIGHTEN));
    	this.highlightColor.setAlpha(192);
    	this.darkColor.setColor(Color.BLACK);
    	this.darkColor.setStyle(Paint.Style.FILL);
    	this.darkColor.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DARKEN));
    	this.darkColor.setAlpha(160);
    	
    }
    
    private Bitmap createOverlayImage(int paramInt, Bitmap paramBitmap){
    	int x = getWindowManager().getDefaultDisplay().getWidth();
    	int y = getWindowManager().getDefaultDisplay().getHeight();
    	Bitmap localBitmap = Bitmap.createBitmap(x, y, Bitmap.Config.ARGB_4444);
        Canvas localCanvas = new Canvas(localBitmap);
        localCanvas.drawBitmap(paramBitmap, x, y, null);
    	return localBitmap;
    }
    
    private Bitmap createDotBasedOnSize(int paramInt){
    	Bitmap localBitmap = Bitmap.createBitmap(paramInt, paramInt, Bitmap.Config.ARGB_4444);
    	 Canvas localCanvas = new Canvas(localBitmap);
    	 localCanvas.drawRect(0.0F, 0.0F, paramInt, paramInt, this.darkColor);
    	 localCanvas.drawCircle(paramInt / 2, paramInt / 2, paramInt / 2 - 1, this.darkColor);
    	 localCanvas.drawCircle(paramInt / 2, paramInt / 2, paramInt / 2 - 1, this.darkColor);
    	 localCanvas.drawCircle(paramInt / 2, paramInt / 2, paramInt / 2 - 2, this.darkColor);
    	 localCanvas.drawCircle(paramInt / 2, paramInt / 2, paramInt / 2 - 2, this.darkColor);

         localCanvas.drawCircle(paramInt / 2, paramInt / 2, paramInt / 2 - 3, this.darkColor);
         localCanvas.drawCircle(paramInt / 2, paramInt / 2, paramInt / 2 - 3, this.highlightColor);
         localCanvas.drawPoint(1 + paramInt / 2, paramInt / 2 - 3, this.highlightColor);
         localCanvas.drawPoint(paramInt / 2, 2 + paramInt / 2, this.highlightColor);
         localCanvas.drawPoint(paramInt / 2 - 2, 2 + paramInt / 2, this.highlightColor);
         localCanvas.drawPoint(paramInt / 2 - 3, 1 + paramInt / 2, this.highlightColor);
       
    	return localBitmap; 
    }
}